package com.lanxiao.cloud.modules.oauth.domain.check;

import com.lanxiao.cloud.common.core.exception.BusinessException;
import com.lanxiao.cloud.common.core.service.check.CheckHandle;
import com.lanxiao.cloud.modules.oauth.domain.model.Role;
import com.lanxiao.cloud.modules.oauth.infrastructure.error.RoleErrorType;
import java.util.Objects;

/**
 * @author ：qiaoliang
 * @date ：2021-09-16
 */
public class CheckRoleHandle extends CheckHandle<Role> {


  protected CheckRoleHandle(Role checkEntity) {
    super(checkEntity);
  }

  public static CheckRoleHandle init(Role role) {
    return new CheckRoleHandle(role);
  }

  /**
   *  校验角色是否存在
   *
   * @author ：qiaoliang
   * @return com.lanxiao.cloud.modules.oauth.domain.check.CheckRoleHandle
   * @date 2021-09-16 10:38
   */
  public CheckRoleHandle checkExist() {
    BusinessException.isNull(checkEntity, RoleErrorType.NO_ROLE_ERROR);
    return this;
  }

  /**
   *  校验标识是否重复
   *
   * @author ：qiaoliang
   * @param mark : 标识
   * @return com.lanxiao.cloud.modules.oauth.domain.check.CheckRoleHandle
   * @date 2021-09-16 10:38
   */
  public CheckRoleHandle checkRepeatMark(String mark) {
    BusinessException.isTrue(Objects.nonNull(checkEntity) && checkEntity.getMark().equals(mark),
        RoleErrorType.MARK_REPEAT_ERROR);
    return this;
  }

}
